package com.vonechina.entity.page;

/**
 * 分页通用类-常用于继承
 * 
 * @author
 *
 */
public class Page {
	/**
	 * 当前页码
	 */
	private int currentPage = 1;
	/**
	 * 每页数据条数
	 */
	private int pageSize = 10;
	/**
	 * 开始数据序号
	 */
	private int begin;
	/**
	 * 结束数据序号
	 */
	private int end;
	/**
	 * 数据总条数
	 */
	private int rows;

	/**
	 * 总页数
	 */
	private int totalPage = 1;

	/**
	 * 是否分页
	 */
	private boolean isPage = true;

	/**
	 * 分页路径
	 */
	private String pageUrl;

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		if (currentPage > 0) {
			this.currentPage = currentPage;
		} else {
			this.currentPage = 1;
		}
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getBegin() {
		begin = (currentPage - 1) * pageSize;
		return begin;
	}

	public int getEnd() {
		end = currentPage * pageSize + 1;
		return end;
	}

	// 设成总条数
	public void setRows(int rows) {
		this.rows = rows;
		/*
		 * 总行数发生改变时,可能引起总页数的变化, 从而可能导致当前页大于总页数,在此处理一下这个情况.
		 */
		if (currentPage > getTotalPage()) {
			currentPage = getTotalPage();
		}

	}

	public int getRows() {
		return rows;
	}

	public int getTotalPage() {
		if (rows % pageSize == 0) {
			totalPage = rows / pageSize;
		} else {
			totalPage = rows / pageSize + 1;
		}
		if (this.totalPage < 1)
			this.totalPage = 1;
		return totalPage;
	}

	public boolean isPage() {
		return isPage;
	}

	public void setPage(boolean isPage) {
		this.isPage = isPage;
	}

	public String getPageUrl() {
		return pageUrl;
	}

	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}

}
